package questionmanager;

import java.awt.Component;
import java.util.EventObject;

import javax.swing.AbstractCellEditor;
import javax.swing.JTable;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;

import rmi.Question;

public class GUIQuestionCellEditor extends AbstractCellEditor implements TableCellEditor,TableCellRenderer{

	private static final long serialVersionUID = 1L;
	private  GUIQuestionCell editor;
	private  GUIQuestionCell renderer;
	
	public GUIQuestionCellEditor(boolean isShowPriority) {
		editor = new GUIQuestionCell(isShowPriority);
		editor.setSelected(true);
		renderer = new GUIQuestionCell(isShowPriority);
	}
	
	
	@Override
	public Object getCellEditorValue() {
		return editor.getQuestion();
	}

	@Override
	public Component getTableCellEditorComponent(JTable table, Object value,
			boolean isSelected, int row, int column) {
		editor.setQuestion((Question)value);
		return editor;
	}

	@Override
	public boolean isCellEditable(EventObject arg0) {
		return true;
	}

	@Override
	public boolean shouldSelectCell(EventObject arg0) {
		return true;
	}

	@Override
	public void cancelCellEditing() {
		super.cancelCellEditing();
	}

	@Override
	public boolean stopCellEditing() {
		return super.stopCellEditing();
	}

	@Override
	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {
		renderer.setSelected(isSelected);
		renderer.setQuestion((Question)value);
		int rowHeight = renderer.getPreferredSize().height;
		table.setRowHeight(row, rowHeight);
		return renderer;
	}
}

